﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
<Serializable()> Public Class MaxTalbeResult

    Private m_MaxCon(-1) As ResultCon '
    Private m_MaxDEPOS(-1) As ResultDEPOS '储存关心点总沉积最大的数据
    Private m_MaxDDEP(-1) As ResultDEPOS '储存关心点浓度最大的数据
    Private m_MaxWDEP(-1) As ResultDEPOS '储存关心点浓度最大的数据
    ''' <summary>
    ''' 最大浓度值数组
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property MaxCon() As ResultCon()
        Get
            Return m_MaxCon
        End Get
        Set(ByVal value As ResultCon())
            m_MaxCon = value
        End Set
    End Property
    ''' <summary>
    ''' 储存总沉积最大的数据
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property MaxDEPOS() As ResultDEPOS()
        Get
            Return m_MaxDEPOS
        End Get
        Set(ByVal value As ResultDEPOS())
            m_MaxDEPOS = value
        End Set
    End Property

    ''' <summary>
    ''' 储存最大干沉积的数据
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property MaxDDEP() As ResultDEPOS()
        Get
            Return m_MaxDDEP
        End Get
        Set(ByVal value As ResultDEPOS())
            m_MaxDDEP = value
        End Set
    End Property
    ''' <summary>
    ''' 储存最大湿沉积的数据
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property MaxWDEP() As ResultDEPOS()
        Get
            Return m_MaxWDEP
        End Get
        Set(ByVal value As ResultDEPOS())
            m_MaxWDEP = value
        End Set
    End Property
    ''' <summary>
    ''' 从AERMOD.OUT文件中获取相应的平均时间内的关心点数据
    ''' </summary>
    ''' <param name="strAERMODOUT">AERMOD.OUT文件内容</param>
    ''' <param name="OutPutOption">OutPutOption对象</param>
    ''' <param name="IsDep">是否考虑沉降</param>
    ''' <param name="strGroup">污染物组源</param>
    ''' <remarks></remarks>
    Public Function GetMaxTalbeDateFromAERMODOUT(ByVal strAERMODOUT As String(), ByVal nMax As Integer, ByVal IsDep As Boolean, ByVal strAerageTime As String, ByVal strGroup As String, ByVal GroupSourceCount As Integer, ByVal version As String) As Boolean
        Dim nVer As Integer = 0
        If version = "07026" Then
            nVer = 0
        ElseIf version = "09292" Then
            nVer = 1
        End If
        ReDim Preserve Me.m_MaxCon(nMax - 1)
        ReDim Preserve Me.m_MaxDEPOS(nMax - 1)
        ReDim Preserve Me.m_MaxDDEP(nMax - 1)
        ReDim Preserve Me.m_MaxWDEP(nMax - 1)
        Dim strLine As String = "" '读取一行
        Dim RowPage As Integer = 0 '用于标记行的页数
        For nAllString As Integer = 0 To strAERMODOUT.Length - 1

            strLine = strAERMODOUT(nAllString) '读取一行
            If strLine.Contains("THE MAXIMUM") And strLine.Contains(strAerageTime) And strLine.Contains("CONCENTRATION") And strLine.Contains(strGroup.ToUpper) Then
                '开始计数
                nAllString += 5
                If GroupSourceCount > 19 Then
                    nAllString += 2
                ElseIf GroupSourceCount > 7 Then
                    nAllString += 1
                End If
                Dim strLineLine4 As String = strAERMODOUT(nAllString)
                If strLineLine4.Contains("RANK") Then '用于判断是不是网格点。如果是按网格点读取数据
                    nAllString += 1
                    '开始读取网格数据
                    Dim strDate As String
                    Dim IsEnd As Boolean = False
                    For i As Integer = RowPage * 40 To RowPage * 40 + 39
                        nAllString += 1
                        strDate = strAERMODOUT(nAllString)
                        Dim nL As Integer = strDate.Substring(nVer + 0, 4)
                        Me.m_MaxCon(nL - 1).x = strDate.Substring(nVer + 35, 10)
                        Me.m_MaxCon(nL - 1).y = strDate.Substring(nVer + 47, 10)
                        Me.m_MaxCon(nL - 1).con = strDate.Substring(nVer + 6, 13)
                        Me.m_MaxCon(nL - 1).dateD = strDate.Substring(nVer + 21, 8)
                        If (i + 1) * 2 <= nMax Then
                            nL = strDate.Substring(nVer + 67, 4)
                            Me.m_MaxCon(nL - 1).x = strDate.Substring(nVer + 102, 10)
                            Me.m_MaxCon(nL - 1).y = strDate.Substring(nVer + 114, 10)
                            Me.m_MaxCon(nL - 1).con = strDate.Substring(nVer + 73, 13)
                            Me.m_MaxCon(nL - 1).dateD = strDate.Substring(nVer + 88, 8)
                        End If
                        If (i + 1) * 2 >= nMax Then
                            IsEnd = True
                            RowPage = 0
                            Exit For
                        End If
                    Next
                    If IsEnd = False Then
                        RowPage += 1
                    End If
                End If
            ElseIf strLine.Contains("THE MAXIMUM") And strLine.Contains(strAerageTime) And strLine.Contains("TOTAL DEPOSITION") And strLine.Contains(strGroup.ToUpper) Then
                '开始计数
                nAllString += 5
                If GroupSourceCount > 19 Then
                    nAllString += 2
                ElseIf GroupSourceCount > 7 Then
                    nAllString += 1
                End If
                Dim strLineLine4 As String = strAERMODOUT(nAllString)
                If strLineLine4.Contains("RANK") Then '用于判断是不是网格点。如果是按网格点读取数据
                    nAllString += 1
                    '开始读取网格数据
                    Dim strDate As String
                    Dim IsEnd As Boolean = False
                    For i As Integer = RowPage * 40 To RowPage * 40 + 39
                        nAllString += 1
                        strDate = strAERMODOUT(nAllString)
                        Dim nL As Integer = strDate.Substring(nVer + 0, 4)
                        Me.m_MaxDEPOS(nL - 1).x = strDate.Substring(nVer + 35, 10)
                        Me.m_MaxDEPOS(nL - 1).y = strDate.Substring(nVer + 47, 10)
                        Me.m_MaxDEPOS(nL - 1).DEPOS = strDate.Substring(nVer + 6, 13)
                        Me.m_MaxDEPOS(nL - 1).dateD = strDate.Substring(nVer + 21, 8)
                        If (i + 1) * 2 <= nMax Then
                            nL = strDate.Substring(nVer + 67, 4)
                            Me.m_MaxDEPOS(nL - 1).x = strDate.Substring(nVer + 102, 10)
                            Me.m_MaxDEPOS(nL - 1).y = strDate.Substring(nVer + 114, 10)
                            Me.m_MaxDEPOS(nL - 1).DEPOS = strDate.Substring(nVer + 73, 13)
                            Me.m_MaxDEPOS(nL - 1).dateD = strDate.Substring(nVer + 88, 8)
                        End If
                        If (i + 1) * 2 >= nMax Then
                            IsEnd = True
                            RowPage = 0
                            Exit For
                        End If
                    Next
                    If IsEnd = False Then
                        RowPage += 1
                    End If
                End If
            ElseIf strLine.Contains("THE MAXIMUM") And strLine.Contains(strAerageTime) And strLine.Contains("DRY DEPOSITION") And strLine.Contains(strGroup.ToUpper) Then
                '开始计数
                nAllString += 5
                If GroupSourceCount > 19 Then
                    nAllString += 2
                ElseIf GroupSourceCount > 7 Then
                    nAllString += 1
                End If
                Dim strLineLine4 As String = strAERMODOUT(nAllString)
                If strLineLine4.Contains("RANK") Then '用于判断是不是网格点。如果是按网格点读取数据
                    nAllString += 1
                    '开始读取网格数据
                    Dim strDate As String
                    Dim IsEnd As Boolean = False
                    For i As Integer = RowPage * 40 To RowPage * 40 + 39
                        nAllString += 1
                        strDate = strAERMODOUT(nAllString)
                        Dim nL As Integer = strDate.Substring(nVer + 0, 4)
                        Me.m_MaxDDEP(nL - 1).x = strDate.Substring(nVer + 35, 10)
                        Me.m_MaxDDEP(nL - 1).y = strDate.Substring(nVer + 47, 10)
                        Me.m_MaxDDEP(nL - 1).DEPOS = strDate.Substring(nVer + 6, 13)
                        Me.m_MaxDDEP(nL - 1).dateD = strDate.Substring(nVer + 21, 8)
                        If (i + 1) * 2 <= nMax Then
                            nL = strDate.Substring(nVer + 67, 4)
                            Me.m_MaxDDEP(nL - 1).x = strDate.Substring(nVer + 102, 10)
                            Me.m_MaxDDEP(nL - 1).y = strDate.Substring(nVer + 114, 10)
                            Me.m_MaxDDEP(nL - 1).DEPOS = strDate.Substring(nVer + 73, 13)
                            Me.m_MaxDDEP(nL - 1).dateD = strDate.Substring(nVer + 88, 8)
                        End If
                        If (i + 1) * 2 >= nMax Then
                            IsEnd = True
                            RowPage = 0
                            Exit For
                        End If
                    Next
                    If IsEnd = False Then
                        RowPage += 1
                    End If
                End If
            ElseIf strLine.Contains("THE MAXIMUM") And strLine.Contains(strAerageTime) And strLine.Contains("WET DEPOSITION") And strLine.Contains(strGroup.ToUpper) Then
                '开始计数
                nAllString += 5
                If GroupSourceCount > 19 Then
                    nAllString += 2
                ElseIf GroupSourceCount > 7 Then
                    nAllString += 1
                End If
                Dim strLineLine4 As String = strAERMODOUT(nAllString)
                If strLineLine4.Contains("RANK") Then '用于判断是不是网格点。如果是按网格点读取数据
                    nAllString += 1
                    '开始读取网格数据
                    Dim strDate As String
                    Dim IsEnd As Boolean = False
                    For i As Integer = RowPage * 40 To RowPage * 40 + 39
                        nAllString += 1
                        strDate = strAERMODOUT(nAllString)
                        Dim nL As Integer = strDate.Substring(nVer + 0, 4)
                        Me.m_MaxWDEP(nL - 1).x = strDate.Substring(nVer + 35, 10)
                        Me.m_MaxWDEP(nL - 1).y = strDate.Substring(nVer + 47, 10)
                        Me.m_MaxWDEP(nL - 1).DEPOS = strDate.Substring(nVer + 6, 13)
                        Me.m_MaxWDEP(nL - 1).dateD = strDate.Substring(nVer + 21, 8)
                        If (i + 1) * 2 <= nMax Then
                            nL = strDate.Substring(nVer + 67, 4)
                            Me.m_MaxWDEP(nL - 1).x = strDate.Substring(nVer + 102, 10)
                            Me.m_MaxWDEP(nL - 1).y = strDate.Substring(nVer + 114, 10)
                            Me.m_MaxWDEP(nL - 1).DEPOS = strDate.Substring(nVer + 73, 13)
                            Me.m_MaxWDEP(nL - 1).dateD = strDate.Substring(nVer + 88, 8)
                        End If
                        If (i + 1) * 2 >= nMax Then
                            IsEnd = True
                            RowPage = 0
                            Exit For
                        End If
                    Next
                    If IsEnd = False Then
                        RowPage += 1
                    End If
                End If

            End If
        Next
        Return True
    End Function
End Class
